import Vue from 'vue'
import VueRouter from 'vue-router'

const Login =()=>import("../views/user/login.vue")
const Register = () => import("../views/user/register")
const Index = () => import("../views/index/index.vue")
const page404 = () => import("../views/404/404.vue")
const Blog = () => import("../views/blog/blogItem.vue")
const Detail = () => import("../views/blog/blogDetail.vue")
const Advice =() =>import("../views/advice/MyMessage.vue")
const Socket =() =>import("../views/socket/socket.vue")
const friend =()=>import("../views/friend/friend.vue")
const Me = ()=>import("../views/Me/blogger.vue")
const chatRoom = ()=>import("../views/chatRoom/chatRoom.vue")
const Mine = ()=>import("../views/mine/mine.vue")

Vue.use(VueRouter)
  const routes = [
    {path:"/",redirect:"/index"},
      {path:"/first",redirect:"/index",component:Index,children:[
        {path:"/index",component:Blog},
        {path:"/detail/:id",component:Detail},
        {path:"/message",component:Advice},
        {path:"/chat",component:Socket},
        {path:'/friend',component:friend},
        {path:'/chatRoom',component:chatRoom},
        {path:'/mine',component:Mine},
        {path:'/me',component:Me},
      ]},
      {path:"/login",component:Login},
      {path:"/register",component:Register},
      {path:"*",component:page404}
]

const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})

router.beforeEach((to, from, next) => {
  console.log(to)
  let weather = document.querySelector("#weather")
  console.log(weather.style);
  
  to.fullPath==="/index"?weather.style.zIndex="100":weather.style.zIndex="-100"
  next()
})



export default router
